package com.cmower.baeldung.string1;

import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Optional;

public class RemoveLastStringTest {
    public static void main(String[] args) {
String s = "沉默王二";
StringUtils.substring(s, 0, s.length() - 1);

        StringUtils.chop(s);
        System.out.println(s.replaceAll(".$",""));

       String result= (s == null) ? null : s.replaceAll(".$", "");

String result1 = Optional.ofNullable(s)
       .map(str -> str.replaceAll(".$", ""))
       .orElse(s);
    }

    public static String removeLastChar(String s) {
        return (s == null || s.length() == 0)
                ? null
                : (s.substring(0, s.length() - 1));
    }
}
